const axios = require('axios');

const url = 'http://httpbin.org/get';

// 定义我们要伪装的请求头
const myHeaders = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'
};

async function sendDisguisedRequest() {
    try {
        // 在请求配置中，通过 `headers` 字段传入我们自定义的头信息
        const response = await axios.get(url, { headers: myHeaders });

        console.log('伪装后，服务器看到的 User-Agent 是:');
        console.log(response.data.headers['User-Agent']);
    } catch (error) {
        console.error('请求出错了:', error.message);
    }
}

sendDisguisedRequest();